home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / getfil2r / form1.frm < prev   
Text File  |  1999-08-16  |  18KB  |  765 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "Form1"
  4.    ClientHeight    =   5010
  5.    ClientLeft      =   60
  6.    ClientTop       =   345
  7.    ClientWidth     =   8970
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   5010
  10.    ScaleWidth      =   8970
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox txtNumPoints 
  13.       Height          =   285
  14.       Left            =   1755
  15.       TabIndex        =   18
  16.       Text            =   "1024"
  17.       Top             =   4050
  18.       Width           =   735
  19.    End
  20.    Begin VB.Frame Frame3 
  21.       Caption         =   "Smoothing Algorithm"
  22.       Height          =   1140
  23.       Left            =   135
  24.       TabIndex        =   15
  25.       Top             =   90
  26.       Width           =   2850
  27.       Begin VB.OptionButton Option1 
  28.          Caption         =   "FFT"
  29.          Height          =   195
  30.          Index           =   1
  31.          Left            =   225
  32.          TabIndex        =   17
  33.          Top             =   720
  34.          Width           =   2040
  35.       End
  36.       Begin VB.OptionButton Option1 
  37.          Caption         =   "Savitzky-Golay"
  38.          Height          =   375
  39.          Index           =   0
  40.          Left            =   225
  41.          TabIndex        =   16
  42.          Top             =   270
  43.          Width           =   2040
  44.       End
  45.    End
  46.    Begin VB.TextBox txtRandom 
  47.       Height          =   330
  48.       Left            =   7200
  49.       TabIndex        =   11
  50.       Text            =   "1"
  51.       Top             =   4545
  52.       Width           =   510
  53.    End
  54.    Begin VB.CommandButton CmdCreateData 
  55.       Caption         =   "Reset Data"
  56.       Height          =   375
  57.       Left            =   3375
  58.       TabIndex        =   1
  59.       Top             =   4500
  60.       Width           =   2445
  61.    End
  62.    Begin VB.PictureBox Pic1 
  63.       BackColor       =   &H80000005&
  64.       Height          =   4200
  65.       Left            =   3195
  66.       ScaleHeight     =   4140
  67.       ScaleWidth      =   5535
  68.       TabIndex        =   0
  69.       Top             =   135
  70.       Width           =   5595
  71.    End
  72.    Begin VB.Frame Frame2 
  73.       Caption         =   "FFT Smooth"
  74.       Height          =   2490
  75.       Left            =   135
  76.       TabIndex        =   7
  77.       Top             =   1350
  78.       Width           =   2895
  79.       Begin VB.HScrollBar HScroll1 
  80.          Height          =   285
  81.          Left            =   135
  82.          Max             =   1024
  83.          Min             =   2
  84.          TabIndex        =   8
  85.          Top             =   1440
  86.          Value           =   100
  87.          Width           =   2535
  88.       End
  89.       Begin VB.Label Label4 
  90.          Caption         =   "Move the scroll bar to smooth using the FFT algorithm"
  91.          Height          =   510
  92.          Left            =   315
  93.          TabIndex        =   14
  94.          Top             =   405
  95.          Width           =   2355
  96.       End
  97.       Begin VB.Label Lblfft 
  98.          AutoSize        =   -1  'True
  99.          Caption         =   "Frequency Cut-Off:  2 %"
  100.          Height          =   195
  101.          Left            =   585
  102.          TabIndex        =   9
  103.          Top             =   1125
  104.          Width           =   1680
  105.       End
  106.    End
  107.    Begin VB.Frame Frame1 
  108.       Caption         =   "Savitzky-Golay Smoothing"
  109.       Height          =   2490
  110.       Left            =   135
  111.       TabIndex        =   2
  112.       Top             =   1350
  113.       Width           =   2895
  114.       Begin VB.CommandButton CmdSG2 
  115.          Caption         =   "Cumulative Smoothing"
  116.          Enabled         =   0   'False
  117.          Height          =   375
  118.          Left            =   180
  119.          TabIndex        =   12
  120.          Top             =   1935
  121.          Width           =   2175
  122.       End
  123.       Begin VB.CommandButton Cmdsg1 
  124.          Caption         =   "Smooth Data"
  125.          Height          =   375
  126.          Left            =   180
  127.          TabIndex        =   6
  128.          Top             =   1440
  129.          Width           =   2175
  130.       End
  131.       Begin VB.ComboBox CboSavGol 
  132.          Height          =   315
  133.          Left            =   1665
  134.          Style           =   2  'Dropdown List
  135.          TabIndex        =   5
  136.          Top             =   405
  137.          Width           =   1095
  138.       End
  139.       Begin VB.CheckBox ChkLog 
  140.          Caption         =   "Log Data"
  141.          Height          =   375
  142.          Left            =   180
  143.          TabIndex        =   4
  144.          ToolTipText     =   "Useful for positive data, spanning several orders of magnitude"
  145.          Top             =   855
  146.          Width           =   1905
  147.       End
  148.       Begin VB.Label Label1 
  149.          Caption         =   "Smoothing Window:"
  150.          Height          =   285
  151.          Left            =   180
  152.          TabIndex        =   3
  153.          Top             =   450
  154.          Width           =   1590
  155.       End
  156.    End
  157.    Begin VB.Label Label6 
  158.       Caption         =   "For speed in FFT, use a power of 2 for the number of points"
  159.       Height          =   420
  160.       Left            =   45
  161.       TabIndex        =   20
  162.       Top             =   4500
  163.       Width           =   2805
  164.    End
  165.    Begin VB.Label Label5 
  166.       Caption         =   "Number of Points:"
  167.       Height          =   240
  168.       Left            =   270
  169.       TabIndex        =   19
  170.       Top             =   4095
  171.       Width           =   1680
  172.    End
  173.    Begin VB.Label Label3 
  174.       Caption         =   "(1 - 5)"
  175.       Height          =   330
  176.       Left            =   7830
  177.       TabIndex        =   13
  178.       Top             =   4590
  179.       Width           =   915
  180.    End
  181.    Begin VB.Label Label2 
  182.       Caption         =   "Randomness:"
  183.       Height          =   330
  184.       Left            =   6075
  185.       TabIndex        =   10
  186.       Top             =   4590
  187.       Width           =   1680
  188.    End
  189. End
  190. Attribute VB_Name = "Form1"
  191. Attribute VB_GlobalNameSpace = False
  192. Attribute VB_Creatable = False
  193. Attribute VB_PredeclaredId = True
  194. Attribute VB_Exposed = False
  195. Option Explicit
  196.  
  197. 'Dynamic data arrays
  198. Dim DataX() As Double
  199. Dim DataY() As Double
  200. Dim SmoothedY() As Double
  201. Dim DataI() As Double
  202.  
  203. Private Const PI As Double = 3.14159265358979
  204.  
  205. Dim NP As Integer
  206. Dim SmoothCount As Integer
  207.  
  208.  
  209. 'The matrix for the Savitzky-Golay Coefficents
  210. 'These are filled in the form load event
  211. Dim SGCoef(1 To 11, 0 To 13) As Integer
  212.  
  213.  
  214. Private Sub CmdCreateData_Click()
  215. Dim i As Integer
  216. Dim Ymin As Double, Ymax As Double
  217. Dim RandFactor As Double
  218.  
  219. Randomize
  220.  
  221. Ymin = 0
  222. Ymax = 0
  223. RandFactor = Val(txtRandom)
  224.  
  225. NP = Val(txtNumPoints)
  226. HScroll1.Max = NP
  227.  
  228. ReDim DataX(1 To NP)
  229. ReDim DataY(1 To NP)
  230. ReDim SmoothedY(1 To NP)
  231. ReDim DataI(1 To NP)
  232.  
  233. For i = 1 To NP
  234.   DataX(i) = i
  235.   DataI(i) = 0
  236.   DataY(i) = Sin(i / NP * 4 * PI) + 0.5 * Sin(i / NP * 40 * PI) + RandFactor * Rnd + 4
  237.   If DataY(i) > Ymax Then Ymax = DataY(i)
  238.   If DataY(i) < Ymin Then Ymin = DataY(i)
  239. Next
  240.  
  241. Pic1.ScaleLeft = 0
  242. Pic1.ScaleWidth = NP
  243.  
  244. Pic1.ScaleTop = Ymax + Ymax * 0.1
  245. Pic1.ScaleHeight = ((Ymax - Ymin)) * -1
  246. GraphData DataY
  247.  
  248. SmoothCount = 0
  249. If Option1(0).Value Then
  250.   Me.Caption = "Savitzky-Golay Smoothing"
  251. Else
  252.   Me.Caption = "FFT Smoothing"
  253. End If
  254. CmdSG2.Enabled = False
  255. HScroll1.SmallChange = NP / 100
  256. HScroll1.LargeChange = NP / 20
  257.  
  258.  
  259.  
  260. End Sub
  261.  
  262. Private Sub Cmdsg1_Click()
  263.  
  264. Call SavGolSmooth(CboSavGol.ListIndex + 2, False)
  265. Me.Caption = "Smoothed " & SmoothCount & " time"
  266. GraphData SmoothedY
  267.  
  268.  
  269.  
  270.  
  271. End Sub
  272.  
  273. Private Sub CmdSG2_Click()
  274.  
  275. Call SavGolSmooth(CboSavGol.ListIndex + 2, True)
  276. Me.Caption = "Smoothed " & SmoothCount & " times"
  277. GraphData SmoothedY()
  278.  
  279. End Sub
  280.  
  281.  
  282.  
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289. Private Sub Form_Activate()
  290.  
  291. Option1(0).Value = True
  292.  
  293. End Sub
  294.  
  295.  
  296.  
  297. Private Sub Form_Load()
  298.  
  299.  
  300. CboSavGol.Clear
  301. CboSavGol.AddItem "5 point"
  302. CboSavGol.AddItem "7 point"
  303. CboSavGol.AddItem "9 point"
  304. CboSavGol.AddItem "11 point"
  305. CboSavGol.AddItem "13 point"
  306. CboSavGol.AddItem "15 point"
  307. CboSavGol.AddItem "17 point"
  308. CboSavGol.AddItem "19 point"
  309. CboSavGol.AddItem "21 point"
  310. CboSavGol.A